home *** CD-ROM | disk | FTP | other *** search
/ PC Home 138 / PC Home issue 138.iso / Software / Essentials / Netscape / nim.xpi / bin / chrome / aim.jar / content / aim / aimHelpers.js < prev    next >
Encoding:
JavaScript  |  2002-10-03  |  51.1 KB  |  1,618 lines

  1. // Various IDL interfaces 
  2. var CachedAimServiceClass = null;
  3. var CachedAimManager = null;
  4. var CachedAimSession = null;
  5. var CachedAimLocateManager = null;
  6. var CachedAimBuddyManager = null;
  7. var CachedAimOdirManager = null;
  8. var CachedAimUserLookupManager = null;
  9. var CachedAimChatManager = null;
  10. var CachedAimTalkAgent = null;
  11. var CachedAimFileXfer = null;
  12. var CachedAimInviteManager = null;
  13. var CachedAimPrivacy = null;
  14. var CachedAimIM = null;
  15. var CachedAimPIM = null;
  16. var CachedAimAdminManager = null;
  17. var CachedAimABInfo = null;
  18. var CachedAimFeedbagManager = null;
  19. var CachedAimWarnings = null;
  20. var CachedAimPrefsManager = null;
  21. var CachedAimStringBundle = null;
  22. var CachedAimSoundManager = null;
  23. var CachedAimDataSource = null;
  24. var CachedAimRDFServiceClass  = null;
  25. var CachedAimRDFService = null;
  26. var CachedAimRDF  = null;
  27. var CachedSessionType= null;
  28. var CachedUserConnection = null;
  29. var disp=new Object();
  30. var cur_val=0;
  31. var cur_name=null;
  32.  
  33.  
  34.  
  35.  
  36. /* Various IDL that represent enumerated types */
  37. var CachedAimAuthorizerState = null;
  38. var CachedAimInsertionStyles = null;
  39. var CachedAimPrivacyModes = null;
  40. var CachedAimTalkAudioMode = null;
  41.  
  42.  
  43. /*
  44.  * Function: aimRDFServiceClass()
  45.  * Arguments: None
  46.  * Return: the cached RDF service class
  47.  * Description: This function checks to see is there is already an existing CachedAimRDFServiceClass.
  48.  * If so, then the cached service class is returned. If not, then the rdf-service object is got from Components.classes
  49.  * and stored as CachedAimRDFSeriveClass.
  50. */
  51.  
  52. function aimRDFServiceClass() 
  53. {
  54.      try {
  55.       if (CachedAimRDFServiceClass == null)
  56.         CachedAimRDFServiceClass = Components.classes["@mozilla.org/rdf/rdf-service;1"];
  57.   } catch (e) {};
  58.   return CachedAimRDFServiceClass;
  59. }
  60.  
  61. /*
  62.  * Function: aimRDF()
  63.  * Arguments: None
  64.  * Return: the cached RDF service
  65.  * Description: This function checks to see is there is already an existing CachedAimRDFService.
  66.  * If so, then the cached service is returned. If not, then a getService function is called 
  67.  * on aimRDFServiceClass (See Above) and stored as CachedAimRDFSerive.
  68. */
  69.  
  70. function aimRDF()
  71. {
  72.   try {
  73.       if (CachedAimRDFService == null)
  74.         CachedAimRDFService = aimRDFServiceClass().getService(Components.interfaces.nsIRDFService);
  75.   } catch (e) {};
  76.   return CachedAimRDFService;
  77. }
  78.  
  79. /*
  80.  * Function: aimRDFDataSource()
  81.  * Arguments: None
  82.  * Return: the cached Aim DataSource
  83.  * Description: This function is called whenever the Aim DataSource is needed.
  84.  * This function checks to see is there is already an existing CachedAimDataSource.
  85.  * If so, then the cahced datasource is returned. If not, then an RDFservice is accessed through
  86.  * the RDFclass object from Components.classes array by using getservice. From the RDF service,
  87.  * the aimDataSource is obtained by using getdataSource function. This gets stored in the global 
  88.  * variable CachedAimDataSource and this gets returned.
  89. */
  90.  
  91. function aimRDFDataSource()
  92. {
  93.     try {
  94.         if (CachedAimDataSource == null) {
  95.             var RDFClass = Components.classes["@mozilla.org/rdf/rdf-service;1"];
  96.             var RDF = RDFClass.getService(Components.interfaces.nsIRDFService);
  97.             CachedAimDataSource = RDF.GetDataSource("rdf:AIM");
  98.         }
  99.     } catch (e) {};
  100.  
  101.     return CachedAimDataSource;
  102. }
  103.  
  104. /*
  105.  * Function: aimServiceClass()
  106.  * Arguments: None
  107.  * Return: the cached Aim Service class
  108.  * Description: This function returns the IMService class object.
  109.  * IMService class is one of the classes in the Components.classes array which can be
  110.  * uniquely identified by the ProgID of "@netscape.com/aim/IMManager;1". 
  111. */
  112.  
  113. function aimServiceClass() 
  114. {
  115.   try {
  116.       if (CachedAimServiceClass == null)
  117.         CachedAimServiceClass = Components.classes['@netscape.com/aim/IMManager;1'];
  118.   } catch (e) {};
  119.   return CachedAimServiceClass;
  120. }
  121.  
  122. /*
  123.  * Function: aimManager()
  124.  * Arguments: None
  125.  * Return: the IMManager service
  126.  * Description: This function is called whenever the Aim Manager service is needed.
  127.  * It checks to see if there is an existing instance of CachedAimManager available. If it does, that is returned.
  128.  * If not, then the AimManager service is obtained from the aimServiceClass() (See Above) 
  129.  * and stored in the CachedAimManager which is returned.
  130. */
  131.  
  132. function aimManager()
  133. {
  134.   try {
  135.       if (CachedAimManager == null)
  136.         CachedAimManager = aimServiceClass().getService(Components.interfaces.nsIIMManager);
  137.   } catch (e) {};
  138.   return CachedAimManager;
  139. }
  140.  
  141. /*
  142.  * Function: aimSession()
  143.  * Arguments: None
  144.  * Return: the AimSession interface
  145.  * Description: This function is either returns(if it already exists) or queries for it and
  146.  * holds the nsIAimSession interface in the CachedAimSession global variable.
  147. */
  148.  
  149. function aimSession()
  150. {
  151.   try {
  152.       if(CachedAimSession == null)
  153.         CachedAimSession = aimManager().QueryInterface(Components.interfaces.nsIAimSession);
  154.   } catch (e) {}; 
  155.   return CachedAimSession;
  156. }
  157.  
  158. /*
  159.  * Function: aimPrivacy()
  160.  * Arguments: None
  161.  * Return: the AimPrivacy interface
  162.  * Description: This function either returns(if it already exists) or queries for it and
  163.  * holds the nsIAimPrivacy interface in the CachedAimPrivacy global variable.
  164. */
  165.  
  166. function aimPrivacy()
  167. {
  168.   try {
  169.       if(CachedAimPrivacy == null)
  170.         CachedAimPrivacy = aimManager().QueryInterface(Components.interfaces.nsIAimPrivacy);
  171.   } catch (e) {}; 
  172.   return CachedAimPrivacy;
  173. }
  174.  
  175. /*
  176.  * Function: aimBuddyManager()
  177.  * Arguments: None
  178.  * Return: the AimBuddy interface
  179.  * Description: This function either returns(if it already exists) or queries for it and
  180.  * holds the nsIAimBuddy interface in the CachedAimBuddyManager global variable.
  181. */
  182.  
  183. function aimBuddyManager()
  184. {
  185.   try {
  186.       if(CachedAimBuddyManager == null)
  187.         CachedAimBuddyManager = aimManager().QueryInterface(Components.interfaces.nsIAimBuddy);
  188.   } catch (e) {}; 
  189.   return CachedAimBuddyManager;
  190. }
  191.  
  192. /*
  193.  * Function: aimLocateManager()
  194.  * Arguments: None
  195.  * Return: the AimLocateManager interface
  196.  * Description: This function either returns(if it already exists) or queries for it and
  197.  * holds the nsIAimLocateManager interface in the CachedAimLocateManager global variable.
  198. */
  199.  
  200. function aimLocateManager()
  201. {
  202.   try {
  203.       if(CachedAimLocateManager == null)
  204.         CachedAimLocateManager = aimManager().QueryInterface(Components.interfaces.nsIAimLocateManager);
  205.   } catch (e) {}; 
  206.   return CachedAimLocateManager;
  207. }
  208.  
  209.  
  210. /*
  211.  * Function: aimOdirManager()
  212.  * Arguments: None
  213.  * Return: the AimOdirManager interface
  214.  * Description: This function either returns(if it already exists) or queries for it and
  215.  * holds the nsIAimOdirManager interface in the CachedAimOdirManager global variable.
  216. */
  217.  
  218. function aimOdirManager()
  219. {
  220.   try {
  221.       if(CachedAimOdirManager == null)
  222.         CachedAimOdirManager = aimManager().QueryInterface(Components.interfaces.nsIAimOdirManager);
  223.   } catch (e) {}; 
  224.   return CachedAimOdirManager;
  225. }
  226.  
  227. /*
  228.  * Function: aimUserLookupManager()
  229.  * Arguments: None
  230.  * Return: the AimUserLookupManager interface
  231.  * Description: This function either returns(if it already exists) or queries for it and
  232.  * holds the nsIAimUserLookupManager interface in the CachedAimUserLookupManager global variable.
  233. */
  234.  
  235. function aimUserLookupManager()
  236. {
  237.   try {
  238.       if(CachedAimUserLookupManager == null)
  239.         CachedAimUserLookupManager = aimManager().QueryInterface(Components.interfaces.nsIAimUserLookupManager);
  240.   } catch (e) {}; 
  241.   return CachedAimUserLookupManager;
  242. }
  243.  
  244. /*
  245.  * Function: aimChatManager()
  246.  * Arguments: None
  247.  * Return: the AimChatManager interface
  248.  * Description: This function either returns(if it already exists) or queries for it and
  249.  * holds the nsIAimChatManager interface in the CachedAimChatManager global variable.
  250. */
  251.  
  252. function aimChatManager()
  253. {
  254.   try {
  255.       if(CachedAimChatManager == null)
  256.         CachedAimChatManager = aimManager().QueryInterface(Components.interfaces.nsIAimChatManager);
  257.   } catch (e) {}; 
  258.   return CachedAimChatManager;
  259. }
  260.  
  261. /*
  262.  * Function: aimLocateManager()
  263.  * Arguments: None
  264.  * Return: the AimTalkAgent interface
  265.  * Description: This function either returns(if it already exists) or queries for it and
  266.  * holds the nsIAimTalkAgent interface in the CachedAimTalkAgent global variable.
  267. */
  268.  
  269. function aimTalkAgent()
  270. {
  271.   try {
  272.       if(CachedAimTalkAgent == null)
  273.         CachedAimTalkAgent = aimManager().QueryInterface(Components.interfaces.nsIAimTalkAgent);
  274.   } catch (e) {}; 
  275.   return CachedAimTalkAgent;
  276. }
  277.  
  278.  
  279.  
  280. function fileXfer()
  281. {
  282.   try {
  283.           if(CachedAimFileXfer == null)
  284.             CachedAimFileXfer = aimManager().QueryInterface(Components.interfaces.nsIAimFileXfer);
  285.   } catch (e) {};
  286.   return CachedAimFileXfer;
  287. }
  288.  
  289.  
  290. /*
  291.  * Function: aimInviteManager()
  292.  * Arguments: None
  293.  * Return: the AimInviteManager interface
  294.  * Description: This function either returns(if it already exists) or queries for it and
  295.  * holds the nsIAimInviteManager interface in the CachedAimInviteManager global variable.
  296. */
  297.  
  298. function aimInviteManager()
  299. {
  300.   try {
  301.       if(CachedAimInviteManager == null)
  302.         CachedAimInviteManager = aimManager().QueryInterface(Components.interfaces.nsIAimInviteManager);
  303.   } catch (e) {}; 
  304.   return CachedAimInviteManager;
  305. }
  306.  
  307. /*
  308.  * Function: aimSoundManager()
  309.  * Arguments: None
  310.  * Return: the AimSoundManager interface
  311.  * Description: This function either returns(if it already exists) or queries for it and
  312.  * holds the nsIAimSoundManager interface in the CachedAimSoundManager global variable.
  313. */
  314.  
  315. function aimSoundManager()
  316. {
  317.   try {
  318.       if(CachedAimSoundManager == null)
  319.         CachedAimSoundManager = aimManager().QueryInterface(Components.interfaces.nsIAimSoundManager);
  320.   } catch (e) {}; 
  321.   return CachedAimSoundManager;
  322. }
  323.  
  324. /*
  325.  * Function: aimIM()
  326.  * Arguments: None
  327.  * Return: the AimIM interface
  328.  * Description: This function either returns(if it already exists) or queries for it and
  329.  * holds the nsIAimIM interface in the CachedAimIM global variable.
  330. */
  331.  
  332. function aimIM()
  333. {
  334.   try {
  335.       if(CachedAimIM == null)
  336.         CachedAimIM = aimManager().QueryInterface(Components.interfaces.nsIAimIM);
  337.   } catch (e) {}; 
  338.   return CachedAimIM;
  339. }
  340.  
  341. /*
  342.  * Function: aimAdminManager()
  343.  * Arguments: None
  344.  * Return: the AimAdminManager interface
  345.  * Description: This function either returns(if it already exists) or queries for it and
  346.  * holds the nsIAimAdminManager interface in the CachedAimAdminManager global variable.
  347. */
  348.  
  349. function aimAdminManager()
  350. {
  351.   try {
  352.       if(CachedAimAdminManager == null)
  353.         CachedAimAdminManager = aimManager().QueryInterface(Components.interfaces.nsIAimAdminManager);
  354.   } catch (e) {}; 
  355.   return CachedAimAdminManager;
  356. }
  357.  
  358. /*
  359.  * Function: aimABInfo()
  360.  * Arguments: None
  361.  * Return: the AimABInfo interface
  362.  * Description: This function either returns(if it already exists) or queries for it and
  363.  * holds the nsIAimABInfo interface in the CachedAimABInfo global variable.
  364. */
  365.  
  366. function aimABInfo()
  367. {
  368.   try {
  369.       if(CachedAimABInfo == null)
  370.         CachedAimABInfo = aimManager().QueryInterface(Components.interfaces.nsIAimABInfo);
  371.   } catch (e) {}; 
  372.   return CachedAimABInfo;
  373. }
  374.  
  375. /*
  376.  * Function: aimFeedbagManager()
  377.  * Arguments: None
  378.  * Return: the AimFeedbagManager interface
  379.  * Description: This function either returns(if it already exists) or queries for it and
  380.  * holds the nsIAimFeedbagManager interface in the CachedAimFeedbagManager global variable.
  381. */
  382.  
  383. function aimFeedbagManager()
  384. {
  385.   try {
  386.       if(CachedAimFeedbagManager == null)
  387.         CachedAimFeedbagManager = aimManager().QueryInterface(Components.interfaces.nsIAimFeedbagManager);
  388.   } catch (e) {}; 
  389.   return CachedAimFeedbagManager;
  390. }
  391.  
  392. /*
  393.  * Function: aimWarnings()
  394.  * Arguments: None
  395.  * Return: the AimWarnings interface
  396.  * Description: This function either returns(if it already exists) or queries for it and
  397.  * holds the nsIAimWarnings interface in the CachedAimWarnings global variable.
  398. */
  399.  
  400. function aimWarnings()
  401. {
  402.   try {
  403.       if(CachedAimWarnings == null)
  404.         CachedAimWarnings = aimManager().QueryInterface(Components.interfaces.nsIAimWarnings);
  405.   } catch (e) {}; 
  406.   return CachedAimWarnings;
  407. }
  408.  
  409. /*
  410.  * Function: aimPrefsManager()
  411.  * Arguments: None
  412.  * Return: the AimPrefsManager interface
  413.  * Description: This function either returns(if it already exists) or queries for it and
  414.  * holds the nsIAimPrefsManager interface in the CachedAimPrefsManager global variable.
  415. */
  416.  
  417. function aimPrefsManager()
  418. {
  419.   try {
  420.       if(CachedAimPrefsManager == null)
  421.         CachedAimPrefsManager = aimManager().QueryInterface(Components.interfaces.nsIPrefsManager);
  422.   } catch (e) {}; 
  423.   return CachedAimPrefsManager;
  424. }
  425.  
  426. /*
  427.  * Function: aimStringBundle()
  428.  * Arguments: None
  429.  * Return: the AimLocateManager interface
  430.  * Description: This function either returns(if it already exists) or queries for it and
  431.  * holds the nsIStringBundle interface in the CachedAimStringBundle global variable.
  432. */
  433.  
  434. function aimStringBundle()
  435. {
  436.   try {
  437.       if(CachedAimStringBundle == null)
  438.         CachedAimStringBundle = aimManager().QueryInterface(Components.interfaces.nsIStringBundle);
  439.   } catch (e) {}; 
  440.   return CachedAimStringBundle;
  441. }
  442.  
  443.  
  444. // The various enumerated types/interfaces
  445. /*
  446.  * Function: aimInsertionStyles()
  447.  * Arguments: None
  448.  * Return: the AimInsertionStyles  
  449.  * Description: This function either returns(if it already exists) or queries for it and
  450.  * holds the nsIAimInsertionStyles enumerated type in the CachedAimInsertionStyles global variable.
  451. */
  452.  
  453. function aimInsertionStyles()
  454. {
  455.   try {
  456.       if(CachedAimInsertionStyles == null)
  457.         CachedAimInsertionStyles = Components.interfaces.nsAimInsertionStyles;
  458.   } catch (e) {}; 
  459.   return CachedAimInsertionStyles;
  460. }
  461.  
  462. /*
  463.  * Function: aimPrivacyModes()
  464.  * Arguments: None
  465.  * Return: the AimPrivacyModes  
  466.  * Description: This function either returns(if it already exists) or queries for it and
  467.  * holds the nsIAimPrivacyModes enumerated type in the CachedAimPrivacyModes global variable.
  468. */
  469.  
  470. function aimPrivacyModes()
  471. {
  472.   try {
  473.       if(CachedAimPrivacyModes == null)
  474.         CachedAimPrivacyModes = Components.interfaces.nsAimPrivacyModes;
  475.   } catch (e) {}; 
  476.   return CachedAimPrivacyModes;
  477. }
  478.  
  479. /*
  480.  * Function: aimNormalizeScreenName()
  481.  * Arguments: 
  482.  *    oldSN -- The original screen name
  483.  * Return: the normalised formatted screenname  
  484.  * Description: This function takes a screen name and formats all the white space charaters with 
  485.  * empty string and converts the screen name into lowercase word.
  486. */
  487.  
  488. function aimNormalizeScreenName(oldSN)
  489. {
  490.     return (oldSN.replace(/\s/gi,"")).toLowerCase();
  491. }
  492.  
  493. /*
  494.  * Function: aimIsSameScreenName()
  495.  * Arguments: 
  496.  *  sN1 -- Screen name one
  497.  *  sN2 --  Screen name two
  498.  * Return: true if both screen names are same, false if not  
  499.  * Description: It is is used to know if two formatted screen names are the same.
  500.  * The aimNormalizeScreenName (See Above) function is used to get the formatted screen names.
  501. */
  502.  
  503. function aimIsSameScreenName(sN1, sN2)
  504. {
  505.      return (aimNormalizeScreenName(sN1) == aimNormalizeScreenName(sN2))
  506. }
  507.  
  508. /* 
  509.  * Function: aimMigrateBuddyList( who )
  510.  * Arguments: 
  511.  *    who --  screen name whose buddy list needs to be migrated.
  512.  * Return: None
  513.  * Description: This function is used to migrate the buddylist of the screen name with
  514.  * which the user has signed on to the aim session. This used thr AimMigratorMigrateBuddyList 
  515.  * function of the AimMigrator service which does the actual migration.
  516.  *
  517. */
  518.  
  519. function aimMigrateBuddyList( who )
  520. {
  521.     var whoMigrate = aimPrefsManager().GetCharPref("aim.session.migrateBuddyList",null, true);
  522.     if ( !whoMigrate || whoMigrate == null || whoMigrate == undefined || whoMigrate != who ) {
  523.         return;
  524.     }
  525.     var IMServiceClass;
  526.     var pAimMigrator;
  527.     try { 
  528.         IMServiceClass = Components.classes['@netscape.com/aim/AimMigrator;1'];
  529.         if ( IMServiceClass != null ) {
  530.             try {
  531.                 pAimMigrator = IMServiceClass.getService(Components.interfaces.nsIAimMigrator);
  532.                 if ( pAimMigrator != null ) {
  533.                     pAimMigrator.AimMigratorMigrateBuddyList( who );
  534.                     aimPrefsManager().SetCharPref("aim.session.migrateBuddyList", "nobody", null, true);
  535.                 }
  536.             }
  537.             catch ( exception ) {
  538.                 // nothing
  539.             }
  540.         }
  541.     }
  542.     catch ( exception ) {
  543.         // nothing
  544.     }
  545. }
  546.  
  547. /*
  548.  * Function: html( node )
  549.  * Arguments: 
  550.  *    node  --  the parent node
  551.  * Return: the entire text content of the document tree
  552.  * Description: This function recursively walks through the entire conversation window doucment
  553.  * and stores all the values in the variable answer.
  554.  *
  555. */
  556.  
  557. function html(node)
  558. {
  559.     var answer = "";
  560.     var type = node.nodeType;
  561.     if (type == Node.ELEMENT_NODE) {
  562.       answer += "<" + node.tagName;
  563.         attributes = node.attributes;
  564.         if (null != attributes) {
  565.             var countAttrs = attributes.length;
  566.             var index = 0;
  567.             while(index < countAttrs) {
  568.                 att = attributes[index];
  569.                 if (null != att) {
  570.                     answer += " " + att.name + "=\"" + att.value + "\"";
  571.                 }
  572.                 index++
  573.             }
  574.         }
  575.  
  576.         // close tag
  577.         answer += ">";
  578.  
  579.         // recursively dump the children
  580.         if (node.hasChildNodes()) {
  581.             // get the children
  582.             var children = node.childNodes;
  583.             var length = children.length;
  584.             var count = 0;
  585.             while(count < length) {
  586.                 child = children[count]
  587.                 answer += html(child)
  588.                 count++
  589.             }
  590.             answer += "</" + node.tagName + ">";
  591.         }
  592.  
  593.  
  594.     }
  595.     // if it's a piece of text just dump the text
  596.     else if (type == Node.TEXT_NODE) {
  597.         answer += node.data;
  598.     }
  599.     return answer;
  600. }
  601.  
  602. /*
  603.  * Function: createInstance( contractid, iidName  )
  604.  * Arguments: 
  605.  *    contractid  --  'ProgID' of the component class.
  606.  *    iidName -- Interface id for the object
  607.  * Return: the XPConnect wrapper for the object with the given iid
  608.  * Description: This function is used to create an instance of class. According to the progID
  609.  * and interface ID, the instance gets created and returned.
  610.  *
  611. */
  612.  
  613. function createInstance( contractid, iidName ) {
  614.   var iid = eval( "Components.interfaces." + iidName );
  615.   return Components.classes[ contractid ].createInstance( iid );
  616. }
  617.  
  618. /*
  619.  * Function: cmdFileSave()
  620.  * Arguments: None
  621.  * Return: None;
  622.  * Description: This function is called from File_>Save menu option in the IM window.
  623.  * It takes the converstaion window document and recursively walk through each documentElement
  624.  * and stores them in a variable called answer. After traversing the entire document,
  625.  * it displays the file picker dialog. Once the user chooses a filename, the SaveConversation
  626.  * function is used to write the contents of variable into the chosen file.
  627. */
  628.  
  629. function cmdFileSave()
  630. {
  631.   var answer;
  632.   var wind = top.frames["LogWnd"];
  633.   if ( wind ) {
  634.       myhead = wind.document.getElementsByTagName("HEAD").item(0);
  635.         if (myhead == null) {
  636.             myhead = wind.document.createElement("HEAD");
  637.             myhtml = wind.document.getElementsByTagName("HTML").item(0);
  638.             myhtml.appendChild(myhead);
  639.         }
  640.         mymeta = wind.document.createElement("META");
  641.         mymeta.setAttribute("HTTP-EQUIV", "Content-Type");
  642.         mymeta.setAttribute("CONTENT", "text/html; charset=UTF-8");
  643.         myhead.appendChild(mymeta);
  644.     answer = html(wind.document.documentElement);
  645.     answer += "\n";
  646.   }
  647.   else {
  648.     return;
  649.   }
  650.   try {
  651.     var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
  652.     // XXX i18n
  653.     fp.init(window, aimString( "title.saveconversation" ),  nsIFilePicker.modeSave);
  654.     fp.appendFilters(nsIFilePicker.filterHTML | nsIFilePicker.filterAll );
  655.         var returnCode = fp.show();
  656.     if (returnCode == nsIFilePicker.returnOK || returnCode == nsIFilePicker.returnReplace) {
  657.           var pPAimIM = aimPIMObject();
  658.             if (pPAimIM) {
  659.         pPAimIM.SaveConversation(fp.file.path, answer);
  660.             }
  661.     }
  662.   } catch (ex) {
  663.                    }
  664. }
  665.  
  666. /*
  667.  * Function: cmdFileClose()
  668.  * Arguments: None
  669.  * Return: None
  670.  * Description: This function is called from File_>Close menu item.
  671.  * It closes the current window( does not exit app).
  672. */
  673.  
  674. function cmdFileClose()
  675. {
  676.   top.close();
  677. }
  678.  
  679. /*
  680.  * Function: cmdFilePrint()
  681.  * Arguments: None 
  682.  * Return: None
  683.  * Description: This function is used to print the IM conversation window. 
  684.  * It accesses the Log window and calls the print function to print the contents.
  685. */
  686.  
  687. function cmdFilePrint(window)
  688. {
  689.   switch(window) {
  690.   case "im":
  691.           if (top.frames["LogWnd"].document.documentElement.lastChild.firstChild != null) {
  692.             // print the contents of log window
  693.             top.frames["LogWnd"].print();
  694.             return;
  695.           }
  696.           // No log window yet - print the compose window
  697.           top.editorShell.Print();
  698.           break;
  699.   case "chat":
  700.           top.frames["LogWnd"].print();
  701.           break;
  702.   }
  703. }
  704.  
  705. /*
  706.  * Function: getEnums( myInterface )
  707.  * Arguments: 
  708.  *    myInterface --  Interface whose enums needs to be obtained 
  709.  * Return: all the enumerated types in the interface
  710.  * Description: This function is used to get all the enumerated types defined in the interface.
  711.  * It loops through all the variables and checks to see if it is of type number. If it is then,
  712.  * it stores all the enums os that variable in a array called enums which is returned.
  713. */
  714.  
  715. function getEnums( myInterface )
  716. {
  717.   var enums = {};
  718.   for ( var i in myInterface ) {
  719.     if ( typeof myInterface[i] == "number" ) {
  720.       enums[i] = myInterface[i];
  721.     }
  722.   }
  723.   return enums;
  724. }
  725.  
  726. /*
  727.  * Function: MigrateDiscover()
  728.  * Arguments: None
  729.  * Return: Boolean
  730.  * Description: This function uses the Aim migrator serice to see what instant messenger 
  731.  * has been used ( to migrate from). Once that version  has been determined, it then checks
  732.  * to see if there is any defaultscreen name and password stored.
  733.  * Return true, if present. Return false if not and set screen name and password to be empty.
  734. */
  735.  
  736. function MigrateDiscover()
  737. {
  738.   var IMServiceClass;
  739.   var pAimMigrator;
  740.     try { 
  741.       IMServiceClass = Components.classes['@netscape.com/aim/AimMigrator;1'];
  742.         if ( IMServiceClass != null ) {
  743.             try {
  744.                 pAimMigrator = IMServiceClass.getService(Components.interfaces.nsIAimMigrator);
  745.                 if ( pAimMigrator != null ) {
  746.                     version = pAimMigrator.AimMigratorDiscover();
  747.                     parent.migrationSource = version;
  748.                     if ( version == null || version == "" ) {
  749.                         return false;
  750.                     }
  751.  
  752.                     var stringPref = {};
  753.                     var stringPref2 = {};
  754.                     var enums = getEnums( Components.interfaces.nsIAimMigrator );
  755.                     // get the default screen name
  756.  
  757.                     var ret = pAimMigrator.AimMigratorGetStringPref2( enums.DefaultScreenName, stringPref, stringPref2 );
  758.  
  759.                     if ( ret == true ) {
  760.                         parent.migrationScreenName = stringPref.value;
  761.                         parent.migrationPassword = stringPref2.value;
  762.                     }
  763.                     else {
  764.                         parent.migrationScreenName = "";
  765.                         parent.migrationPassword = "";
  766.                     }
  767.  
  768.                     // get the remaining screen names, if any
  769.                     var stringPrefVec = {}; 
  770.                     var vecSize = {};
  771.                     stringPrefVec = pAimMigrator.AimMigratorGetStringVectorPref( enums.ScreenName, vecSize );
  772.  
  773.                     var i;
  774.                     parent.migrationScreenNameVecSize = vecSize;
  775.                     parent.migrationScreenNameVec = stringPrefVec;
  776.  
  777.                     return ret;        // all we care about is did we get a default screenname
  778.                 }
  779.             }
  780.             catch(exception) {
  781.                 return false;
  782.             }
  783.         }    
  784.     }
  785.   catch(exception) {
  786.         return false;
  787.     }
  788. }
  789.  
  790. /*
  791.  * Function: AimOnlineAway()
  792.  * Arguments: None 
  793.  * Return: Boolean
  794.  * Description: This function is used to check whether user is in away state. 
  795.  * This function uses the RDF service to access Aim Session from the Aimdatasource.
  796.  * From the aimSession, the value of the Sessionstate is retrieved and checked to see if it
  797.  * is "OnlineAway". If it is return true, otherwise return false.
  798. */
  799.  
  800. function AimOnlineAway()
  801. {
  802.     var SessionState = aimRDF().GetResource("http://home.netscape.com/NC-rdf#OnlineState");
  803.     var dataSource = aimRDFDataSource();
  804.     var AimSession = aimRDF().GetResource("NC:AIM/Session");
  805.     var target = dataSource.GetTarget(AimSession, SessionState, true);
  806.     var state = target.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  807.     if ("OnlineAway" == state)
  808.         return true;
  809.     return false;
  810. }
  811.  
  812. /*
  813.  * Function: ComeBack()
  814.  * Arguments: None 
  815.  * Return: None
  816.  * Description: This function is used when the I'mBack button is clicked or 
  817.  * whenever the user needs to get out of the "Away" state. It sets a null away message
  818.  * using the SetUserInfoAwayMessage function. 
  819. */
  820.  
  821. function ComeBack()
  822. {
  823.     locateManager = aimLocateManager();
  824.     if ( locateManager ) 
  825.         locateManager.SetUserInfoAwayMessage(null);
  826. }
  827.  
  828. /*
  829.  * Function: AimtoOpenWindowByType( inType, uri )
  830.  * Arguments:  
  831.  *    inType  --  name of the window type
  832.  *    uri   --  uri of the window to be opened
  833.  * Return: None
  834.  * Description: This function uses the windows mediator service to get the most recent window
  835.  * of the given type. If there is a window with the same type, then that window is brought to 
  836.  * focus. If no window exists, then a new window get opened.
  837. */
  838.  
  839. function AimtoOpenWindowByType( inType, uri )
  840. {
  841.   var windowManager = Components.classes['@mozilla.org/rdf/datasource;1?name=window-mediator'].getService();
  842.   var     windowManagerInterface = windowManager.QueryInterface( Components.interfaces.nsIWindowMediator);
  843.   var topWindow = windowManagerInterface.getMostRecentWindow( inType );
  844.   if ( topWindow ) {
  845.     topWindow.focus();
  846.   } 
  847.   else
  848.     window.openDialog(uri, "_blank", "chrome,all,dialog=no", "Setup");
  849. }                     
  850.  
  851. /*
  852.  * Function: aimGlobalCmdHelp()
  853.  * Arguments: None 
  854.  * Return: None
  855.  * Description: For netbusiness instant messenger client, this will call the AimtoOpenWindwoByType 
  856.  * (See Above) function with help_nim.xul. For NIM, it is called with help.xul?im. 
  857.  * These files in turn contain the help contents for the respective products.
  858. */
  859.  
  860. function aimGlobalCmdHelp()
  861. {
  862.    if (isIcq()) {
  863.        AimtoOpenWindowByType("help:icq","chrome://help/content/help.xul?icq"); 
  864.    }
  865.    else {
  866.           AimtoOpenWindowByType("help:im","chrome://help/content/help.xul?im"); 
  867.    }
  868. }
  869.     
  870.  
  871. /*
  872.  * Function: AimgoClickThrobber(urlPref)
  873.  * Arguments: 
  874.  *  urlPref --  input url which should be loaded
  875.  * Return: None
  876.  * Description: For netbusiness instant messenger client, this will get the localised url.
  877.  * This url is then loaded in the default browser.
  878.  * for NIM, this just loads the given url in the browser.
  879. */
  880.  
  881. function AimgoClickThrobber(urlPref)
  882. {
  883.         goClickThrobber( urlPref );
  884. }
  885.  
  886. /*
  887.  * Function: GetRdfFileUrl(def_name, chg_name)
  888.  * Arguments: 
  889.  *    def_name  --  default file that needs to be copied in the case of new profile  
  890.  *    chg_name  --  the name of the file which will be appended to screen name and stores the data.
  891.  * Return: the url of the file
  892.  * Description: This function is used to get the rdf file for away messages/sign on a friend invites 
  893.  * for a given screen name. Using the directory service, the default profile and the user profile is
  894.  * obtained.  A default file is created by making a copy of the default profile file.
  895.  * This will be named after the def_name (first input parameter). e.g. in the case of away messages 
  896.  * it will be called default-messages.rdf.  A new file which is a copy of the user's profile is created.
  897.  * It will be named after the screen name for the current session. According to the second input 
  898.  * parameter it will be further identified. So e.g. in case of away message, the file will be named 
  899.  * as <screenname><chg_name>.rdf. If this file cannot be created from the user's profile, then default 
  900.  * profile file is copied over and this will now be called after the session's screen name and chg_name param. 
  901.  * The exact identity and location of this file is then obtained  by using nsIFileURL and 
  902.  * the unique url gets returned.
  903. */
  904. function GetRdfFileUrl(def_name, chg_name)
  905. {                                                                               
  906.     var directoryService  =  Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties);
  907.     var userProfile = directoryService.get("ProfD", Components.interfaces.nsIFile);
  908.     var defaultProfile = directoryService.get("profDef", Components.interfaces.nsIFile); // profile defaults
  909.     if (!defaultProfile.exists())                                   
  910.         defaultProfile = directoryService.get("ProfDefNoLoc", Components.interfaces.nsIFile); // profile defaults
  911.     var defaultInviteFile = defaultProfile.clone();                         
  912.     defaultInviteFile.append(def_name);                                     
  913.   var screenName = "";                                                
  914.   myPref = aimPrefsManager();                                         
  915.   if ( myPref ) {                                                         
  916.       try {                                                           
  917.             screenName = myPref.GetCharPref( "aim.session.screenname" , null, false);
  918.           }
  919.       catch(e) {                                                      
  920.              screenName = "";                                        
  921.                }
  922.     }   
  923.     if ( screenName != "" ) {                                               
  924.         screenName = screenName + ".";                                  
  925.   }
  926.     else                                                            
  927.   {
  928.       return;                                         
  929.   }
  930.     var InviteListFile = userProfile.clone();
  931.     InviteListFile.append(screenName+chg_name);                             
  932.     if (!InviteListFile.exists()) {                                         
  933.           try {
  934.               defaultInviteFile.copyTo(userProfile,screenName+chg_name);     
  935.         }
  936.             catch (e) {
  937.                       }
  938.             InviteListFile = userProfile.clone();                           
  939.       InviteListFile.append(screenName+chg_name);                     
  940.       if (!InviteListFile.exists())    {
  941.         // Something is wrong - This should never happen
  942.         return;
  943.       }                               
  944.     }                                                                       
  945.   var InviteFileURL = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIFileURL);
  946.     InviteFileURL.file = InviteListFile;
  947.     return( InviteFileURL.spec );                                           
  948. }  
  949.  
  950. /*
  951.  * Function: getsidebarframe()
  952.  * Arguments: None
  953.  * Return: the frame which contains the sidebarbarpanel.xul
  954.  * Description: This function walks through the list of frames. If there is only one frame, then that frame is
  955.  * returned. Otherwise from the list, the frame which contains SidebarPanel.xul is returned.
  956. */
  957.  
  958. function getsidebarframe()
  959. {
  960.   var frame_list=window.frames;
  961.      if (frame_list.length==0)
  962.        return window;
  963.   for (var i=0; i<frame_list.length; i++) {
  964.        if (frame_list[i].location =="chrome://aim/content/SidebarPanel.xul")
  965.              return frame_list[i];
  966.      }
  967.     return window;    
  968.                                                                              
  969. function aimString(name)
  970. {
  971.  
  972.     var myAimSession = aimSession();
  973.     if ( myAimSession ) {
  974.         var pIStringBundle = aimSession().QueryInterface(Components.interfaces.nsIStringBundle);
  975.         if (pIStringBundle)
  976.             return pIStringBundle.GetStringFromName(name);
  977.     }
  978.     return "";
  979. }
  980.  
  981. function aimErrorBox(errorText)
  982. {
  983.     top.alert(errorText);
  984. }
  985.  
  986.  
  987. /*
  988.  * Function: processAwayMsg(msg)
  989.  *
  990.  * Arguments: msg
  991.  * 
  992.  * Return: msg with real away msgs.
  993.  *
  994.  * Description: This fn takes a msg (like "Hi %n, howdy?") and converts to real away msgs (like "Hi screenname, howdy?").
  995.  *
  996.  * Author: Suresh Kasinathan<suresh@netscape.com> 12/10/01
  997.  *              
  998. */
  999.  
  1000. function processAwayMsg(msg)
  1001. {
  1002.   var sn;
  1003.   var pIAimSession = aimSession();
  1004.   if(pIAimSession)
  1005.     sn = pIAimSession.CurrentScreenName;
  1006.   else
  1007.     sn = "";
  1008.   var date = new Date();
  1009.   var dateService = Components.classes["@mozilla.org/intl/scriptabledateformat;1"].getService(Components.interfaces.nsIScriptableDateFormat);
  1010.   var time =  dateService.FormatTime(
  1011.                               "",
  1012.                               dateService.timeFormatNoSeconds,
  1013.                               date.getHours(),
  1014.                               date.getMinutes(),
  1015.                               date.getSeconds());
  1016.  
  1017.   var day =  dateService.FormatDate(
  1018.                               "",
  1019.                               dateService.dateFormatShort,
  1020.                               date.getFullYear(),
  1021.                               date.getMonth()+1,
  1022.                               date.getDate());
  1023.  
  1024.   msg = msg.replace(/%t/gi, time);
  1025.   msg = msg.replace(/%d/gi, day);
  1026.   msg = msg.replace(/%n/gi, sn);
  1027.   return msg;
  1028. }
  1029.  
  1030.  
  1031.  /******
  1032.   * Returns a string with the difference between two dates looking like: "x days, x hours, x minutes."
  1033.   * Both parameters are dates in seconds since 1/1/1970 00:00:00.
  1034.   ******/
  1035.  
  1036. function getPrettyDateDiff(aDate2, aDate1)
  1037. {
  1038.   var diff = aDate2-aDate1;
  1039.   var pretty = "";
  1040.    
  1041.   var dayDiff = Math.floor(diff / 86400);
  1042.   diff %= 86400;
  1043.   if (dayDiff > 0) {
  1044.     pretty += dayDiff + " day" + (dayDiff == 1 ? "" : "s");
  1045.   }
  1046.    
  1047.   var hourDiff = Math.floor(diff / 3600);
  1048.   diff %= 3600;
  1049.   if (hourDiff > 0) {
  1050.     pretty += (pretty.length > 0 ? ", " : "") + hourDiff + " " + aimString("tooltip.hour") + (hourDiff == 1 ? "" : "s");
  1051.   }
  1052.    
  1053.   var minDiff = Math.floor(diff / 60);
  1054.   if (minDiff > 0) {
  1055.     pretty += (pretty.length > 0 ? ", " : "") + minDiff + " " + aimString("tooltip.minute") + (minDiff == 1 ? "" : "s");
  1056.   }
  1057.    
  1058.   return pretty;
  1059. }
  1060.  
  1061.  
  1062. /*
  1063.  * Function: validateEmailAddress()
  1064.  *
  1065.  * Arguments: email address
  1066.  * 
  1067.  * Return: boolean true if the email address is valid
  1068.  *         boolean false if the email address is invalid
  1069.  *
  1070.  * Description: Called from the above function to validate the email address. Length and special characters are validated.
  1071.  *
  1072.  * Author: Suresh Kasinathan<suresh@netscape.com> 11/15/01
  1073.  *        
  1074. */
  1075.  
  1076. function validateEmailAddress(emailElement)
  1077. {
  1078.   // var email = emailElement.value;
  1079.   var emailArray = emailElement.split('@');
  1080.  
  1081.   if (emailArray.length != 2 ||
  1082.       !emailArray[0].length ||
  1083.       !emailArray[1].length || 
  1084.       containsIllegalCharacter(emailArray[0]) ||
  1085.       containsIllegalCharacter(emailArray[1]) ) {
  1086.         // aimErrorBox(aimString("msg.enterValidEmail"));
  1087.         return false;
  1088.   }
  1089.     
  1090.   return true;
  1091. }
  1092.  
  1093. /*
  1094.  * Function: containsIllegalCharacter()
  1095.  *
  1096.  * Arguments: string
  1097.  * 
  1098.  * Return: boolean true if the string doesnot contain illegal characters.
  1099.  *         boolean false if the string contain illegal characters.
  1100.  *
  1101.  * Description: This function checks for common illegal characters. 
  1102.  *
  1103.  * Author: Suresh Kasinathan<suresh@netscape.com> 11/15/01
  1104.  *        
  1105. */
  1106.  
  1107. function containsIllegalCharacter(aString)
  1108. {
  1109.   for (var i=0; i < aString.length; i++) {
  1110.     var code = aString.charCodeAt(i);
  1111.     if (code > 127)
  1112.       return true; // non-ASCII
  1113.     else if (code == 9 || code == 10 || code == 11 || code == 32)
  1114.       return true; // white space
  1115.     else if (code == 64)
  1116.       return true; // '@'
  1117.   }
  1118.   return false;
  1119.  
  1120.  
  1121. /* Returns the selected tree/tree name based on the selected tab (online or listsetup) */
  1122. function getSelectedTreeName()
  1123. {
  1124.   var sidebarframe=getsidebarframe();
  1125.   var tab = sidebarframe.document.getElementById("OnlineOrgTabPanel");
  1126.   var tree;
  1127.   if (tab.selectedIndex == 0)
  1128.     tree = sidebarframe.document.getElementById("OnlineBuddies");
  1129.   else
  1130.     tree = sidebarframe.document.getElementById("ListSetup");
  1131.  
  1132.   return tree;
  1133. }
  1134.  
  1135. /* Returns the column name for the selected tab*/
  1136. function getSelectedTabName()
  1137. {
  1138.   var sidebarframe=getsidebarframe();
  1139.   var tab = sidebarframe.document.getElementById("OnlineOrgTabPanel");
  1140.   if (tab.selectedIndex == 0)
  1141.     return "BuddiesCol"
  1142.   else
  1143.     return "ListSetupCol"
  1144. }
  1145.  
  1146. /*this returns the target for the given source, attribute(property) in the tree*/
  1147. function GetBuddyAttribute(tree, source, attribute)
  1148. {
  1149.   var RDF = aimRDF();
  1150.   var property = RDF.GetResource("http://home.netscape.com/NC-rdf#" + attribute);
  1151.   var target = tree.database.GetTarget(source, property, true);
  1152.   if (target)
  1153.     target = target.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  1154.   return target;
  1155. }
  1156.  
  1157. /* returns the resource at the given index */
  1158. function GetBuddyResource(tree, index)
  1159. {
  1160.   var RDF = aimRDF();
  1161.   var item = tree.contentView.getItemAtIndex(index);
  1162.   return RDF.GetUnicodeResource(item.id);
  1163. }
  1164.  
  1165. /*
  1166. * Name: getSelectedScreenName
  1167. * Arguments: tree 
  1168. * Description:
  1169. *  This function returns the selected item's screenname value if selected item has this attribute. 
  1170. * Return Value: screenName
  1171. * Author: Prassanna<prass@netscape.com>, Joseph Elwell<jelwell@netscape.com>
  1172. */
  1173.  
  1174. function getSelectedScreenName()
  1175. {
  1176.   var tree = getSelectedTreeName();
  1177.   var col = getSelectedTabName();
  1178.   if (!tree || !col) return;
  1179.   var screenName = null;
  1180.   var currentIndex = tree.currentIndex;
  1181.   if (currentIndex > 0) {
  1182.     var isContainer = tree.treeBoxObject.view.isContainer(currentIndex);
  1183.     //if it is a container (groups or Offline group) return null
  1184.     if (!isContainer) {
  1185.       var buddyResource = GetBuddyResource(tree, currentIndex);
  1186.       var screenName = GetBuddyAttribute(tree, buddyResource, "ScreenName");
  1187.     }
  1188.   }
  1189.   return screenName;
  1190. }
  1191.  
  1192. /*
  1193. * Name: checkInputEmail
  1194. * Arguments: input email value 
  1195. * Description:
  1196. *  This function returns a boolean value based on whether the input is a valid email-address
  1197. * Return Value: boolean
  1198. * Author: Prassanna<prass@netscape.com> 
  1199. */
  1200.  
  1201.  
  1202. function checkInputEmail( email)
  1203. {
  1204.   var emailArray=email.split('@');
  1205.   var emailArray2=email.split('.');
  1206.   var alertText;
  1207.   if (email.length =="") {
  1208.     aimErrorBox(aimString("msg.Invalidemail"));
  1209.     return false;
  1210.   }
  1211.   if (emailArray.length != 2 || emailArray[0] == "" || emailArray[1] == "") {
  1212.     aimErrorBox(aimString("msg.Invalidemail"));
  1213.     return false;
  1214.   }
  1215.   if (emailArray2.length < 2) { 
  1216.     aimErrorBox(aimString("msg.Invalidemail"));
  1217.     return false;
  1218.   }
  1219.   for (i=0; i<emailArray2.length; i++)
  1220.   {
  1221.     if (emailArray2[i] == "") {
  1222.       aimErrorBox(aimString("msg.Invalidemail"));
  1223.       return false;
  1224.     }
  1225.   }
  1226.   return true;
  1227. }
  1228.  
  1229. /*
  1230. * Name: setConnectionInfo
  1231. * Arguments: connectionName, aClient, screenName
  1232. * Description:
  1233. *  This function sets current connection
  1234. * Return Value: true
  1235. * Author: A Averbukh<anatoliya@netscape.com> 
  1236. */
  1237. function setConnectionInfo (connectionName, aClient, screenName)
  1238. {
  1239.     var curSession;
  1240.     if (connectionName =="AIM")
  1241.         curSession = 0;
  1242.     else // ICQ
  1243.         curSession = 2;
  1244.        
  1245.  
  1246.  
  1247.     manPref = aimPrefsManager();
  1248.  
  1249.     var Host           = manPref.GetCharPrefEdit ("aim.session.host",           null, 2, "", curSession);
  1250.     var Port           = manPref.GetIntPrefEdit  ("aim.session.port",           null, 2, "", curSession);
  1251.     var ProxyHost      = manPref.GetCharPrefEdit ("aim.session.proxyhost",      null, 2, "", curSession);
  1252.     var ProxyPort      = manPref.GetIntPrefEdit  ("aim.session.proxyport",      null, 2, "", curSession);
  1253.     var ProxyUser      = manPref.GetWCharPrefEdit("aim.session.proxyuser",      null, 2, "", curSession);
  1254.     var ProxyPassword  = manPref.GetWCharPrefEdit("aim.session.proxypassword",  null, 2, "", curSession);
  1255.     var ProxyProtocol  = manPref.GetIntPrefEdit  ("aim.session.proxyprotocol",  null, 2, "", curSession);
  1256.     var useProxy       = manPref.GetBoolPrefEdit ("aim.session.isproxy",        null, 2, "", curSession);
  1257.     var ConnectionType = manPref.GetIntPrefEdit  ("aim.session.connectiontype", null, 2, "", curSession);                                                
  1258.  
  1259. dump("Host=" + Host + " Port=" + Port + " ProxyHost=" + ProxyHost + " ProxyPort=" + ProxyPort + "\n");
  1260. dump("ProxyUser=" + ProxyUser + " ProxyPassword=" + ProxyPassword + " ProxyProtocol=" + ProxyProtocol + "\n");
  1261. dump("useProxy=" + useProxy + " ConnectionType=" + ConnectionType + "\n");
  1262.  
  1263.  
  1264.     if (aClient == "im") { // internal session
  1265.  
  1266.         manPref.SetIntPrefEdit  ("aim.internal.intsessiontype",  curSession,    
  1267.                                  null, 1, "", -1);
  1268.         manPref.SetWCharPrefEdit("aim.internal.intname",         connectionName, 
  1269.                                  null, 1, "", -1);
  1270.         manPref.SetCharPrefEdit("aim.internal.inthost",             Host,           
  1271.                                  null, 1, "", -1);                  
  1272.         manPref.SetIntPrefEdit  ("aim.internal.intport",            Port,           
  1273.                                  null, 1, "", -1);                  
  1274.         manPref.SetCharPrefEdit("aim.internal.intproxyhost",        ProxyHost,      
  1275.                                  null, 1, "", -1);                  
  1276.         manPref.SetIntPrefEdit  ("aim.internal.intproxyport",       ProxyPort,      
  1277.                                  null, 1, "", -1);                  
  1278.         manPref.SetWCharPrefEdit("aim.internal.intproxyuser",       ProxyUser,      
  1279.                                  null, 1, "", -1);                  
  1280.         manPref.SetWCharPrefEdit("aim.internal.intproxypassword",   ProxyPassword,  
  1281.                                  null, 1, "", -1);                  
  1282.         manPref.SetIntPrefEdit  ("aim.internal.intproxyprotocol",   ProxyProtocol,  
  1283.                                  null, 1, "", -1);
  1284.         manPref.SetBoolPrefEdit ("aim.internal.intisproxy",         useProxy,                 
  1285.                                  null, 1, "", -1);
  1286.         manPref.SetIntPrefEdit  ("aim.internal.intconnectiontype",  ConnectionType,                 
  1287.                                  null, 1, "", -1);                                           
  1288.     }
  1289.     else { //external session
  1290.  
  1291.         manPref.SetIntPrefEdit  ("aim.internal.extsessiontype",  curSession,    
  1292.                                  null, 1, "", -1);
  1293.         manPref.SetWCharPrefEdit("aim.internal.extname",         connectionName, 
  1294.                                  null, 1, "", -1);
  1295.         manPref.SetCharPrefEdit("aim.internal.exthost",           Host,           
  1296.                                  null, 1, "", -1);
  1297.         manPref.SetIntPrefEdit  ("aim.internal.extport",          Port,           
  1298.                                  null, 1, "", -1);
  1299.         manPref.SetCharPrefEdit("aim.internal.extproxyhost",      ProxyHost,      
  1300.                                  null, 1, "", -1);
  1301.         manPref.SetIntPrefEdit  ("aim.internal.extproxyport",     ProxyPort,      
  1302.                                  null, 1, "", -1);
  1303.         manPref.SetWCharPrefEdit("aim.internal.extproxyuser",     ProxyUser,      
  1304.                                  null, 1, "", -1);
  1305.         manPref.SetWCharPrefEdit("aim.internal.extproxypassword", ProxyPassword,  
  1306.                                  null, 1, "", -1);
  1307.         manPref.SetIntPrefEdit  ("aim.internal.extproxyprotocol", ProxyProtocol,  
  1308.                                  null, 1, "", -1);
  1309.         manPref.SetBoolPrefEdit ("aim.internal.extisproxy",       useProxy,   
  1310.                                  null, 1, "", -1);  
  1311.         manPref.SetIntPrefEdit  ("aim.internal.extconnectiontype", ConnectionType,   
  1312.                                  null, 1, "", -1);  
  1313.     }
  1314.  
  1315.     return true;
  1316.     
  1317. }
  1318.  
  1319.  
  1320. /*
  1321.  * Function: GetPanelSessionType 
  1322.  * Arguments: 
  1323.  * Return: the url of the file
  1324.  * Description: returns current pref panel type
  1325.  * The function is used for preferences
  1326.  * Author: A Averbukh<anatoliya@netscape.com> 
  1327. */
  1328.  
  1329. function GetPanelSessionType()
  1330. {
  1331.  
  1332.     if (document.documentElement.getAttribute("isIcqPanel") == "true")
  1333.         return 2;
  1334.     else//AIM
  1335.         return 0;
  1336.  
  1337. }
  1338.  
  1339. /*
  1340.  * Function: CopynGetUrl (def_name, chg_name)
  1341.  * Arguments: 
  1342.  *    def_name  --  default file that needs to be copied in the case of new profile  
  1343.  *    chg_name  --  the name of the file which will be appended to screen name and stores the data.
  1344.  * Return: the url of the file
  1345.  * Description: The same one as GetRdfFileUrl, except: it copies file to user's profile without adding SN to the file name
  1346.  * The function is used for connection settings
  1347. */
  1348. function CopynGetUrl (def_name, chg_name) 
  1349. {
  1350.     var directoryService  =  Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties);
  1351.     
  1352.     var userProfile = directoryService.get("ProfD", Components.interfaces.nsIFile);
  1353.     var defaultProfile = directoryService.get("profDef", Components.interfaces.nsIFile);
  1354.     if (!defaultProfile.exists())                                   
  1355.         defaultProfile = directoryService.get("ProfDefNoLoc", Components.interfaces.nsIFile); 
  1356.  
  1357.  
  1358.     var defaultConnections = defaultProfile.clone();                         
  1359.     defaultConnections.append(def_name);                                 
  1360.  
  1361.     var UserConnections = userProfile.clone();
  1362.     UserConnections.append(chg_name); 
  1363.     
  1364.     if (!UserConnections.exists()) 
  1365.     { 
  1366.       try 
  1367.       {
  1368.         defaultConnections.copyTo(userProfile, chg_name);     
  1369.       }
  1370.       catch (e) 
  1371.       {
  1372.  
  1373.         return null;
  1374.       }
  1375.                       
  1376.       UserConnections = userProfile.clone();                           
  1377.       UserConnections.append(chg_name);   
  1378.  
  1379.     }  
  1380.     
  1381.     var UserConnectionsURL = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIFileURL);
  1382.     UserConnectionsURL.file = UserConnections;
  1383.  
  1384.     return( UserConnectionsURL.spec );
  1385.  
  1386. }
  1387.  
  1388. /*
  1389.  * Function: isIcq
  1390.  * Arguments: 
  1391.  * Return: boolean
  1392.  * Description: returns true is it is icq session, false if not
  1393.   * Author: Prassanna<prass@netscape.com> 
  1394. */
  1395. function isIcq()
  1396. {
  1397.   var SessionType=getCurrentSessionType();
  1398.   if (SessionType == "ICQ")
  1399.   {
  1400.     return true;
  1401.    }
  1402.    return false;
  1403. }
  1404.  
  1405. /*
  1406.  * Function: getCurrentSessionType
  1407.  * Arguments: 
  1408.  * Return: Value of sessionType
  1409.  * Description: If cached sessionType value exists, return that value, else obtain sessionType from prefs.
  1410.  * This will be used in most windows where the user is logged in and is attached to one session and is safe to 
  1411.  * look at cached value.
  1412.  * Author: Prassanna<prass@netscape.com> 
  1413. */
  1414. function getCurrentSessionType()
  1415. {
  1416.  try {
  1417.       // if(CachedSessionType == null)
  1418.             CachedSessionType = aimPrefsManager().GetCharPref("aim.session.userconnectionname", null, true);
  1419.   } catch (e) {}; 
  1420.   return CachedSessionType;
  1421.  }
  1422.  
  1423. function setCurrentSessionType(conval)
  1424. {
  1425.    CachedSessionType=conval;
  1426.    aimPrefsManager().SetCharPref("aim.session.userconnectionname", conval, null, true);
  1427. }
  1428.  
  1429. /*
  1430.  * Function: getSessionType
  1431.  * Arguments: 
  1432.  * Return: Value of sessionType
  1433.  * Description: Obtain the sessionType from prefs everytime. Differnt from the above where a cahced value is used.
  1434.  * This will be used in sidebarpanel and app windows where user could change it before loggin in.
  1435.  * Author: Prassanna<prass@netscape.com> 
  1436. */
  1437.  
  1438. function getSessionType() {
  1439.   return(aimPrefsManager().GetSessionType());
  1440. }
  1441.  
  1442. /*
  1443.  * Function: IsServiceCorrect (curSN, curConnName)
  1444.  * Arguments: 
  1445.  *    curSN        --  cureent SN
  1446.  *    curConnName  --  cureent connection name
  1447.  * Return: true/false 
  1448.  * Description: Check, if curSN can be used to sign on to service curConnName
  1449.  * Author: Anatoliy Averbukh<anatoliya@netscape.com> 
  1450. */
  1451. function IsServiceCorrect (curSN, curConnName)
  1452. {
  1453.    var curTypeperSN = aimPrefsManager().GetSessionTypeEdit (curSN);
  1454.  
  1455.    var nCurConn;
  1456.  
  1457.    if (curConnName =="AIM") {
  1458.       nCurConn = 0;
  1459.    }
  1460.    else if (curConnName =="ICQ"){
  1461.       nCurConn = 2;
  1462.    }
  1463.    else {
  1464.       return false;
  1465.    }
  1466.  
  1467.    if (nCurConn == curTypeperSN) {
  1468.        return true;
  1469.    }
  1470.    else {
  1471.        if (curConnName =="AIM")
  1472.         aimErrorBox(aimString("msg.wrongsrv").replace(/%ScreenName%/, '"' + curSN + '"'));
  1473.        else
  1474.         aimErrorBox(aimString("msgICQ.wrongsrv").replace(/%ScreenName%/, '"' + curSN + '"'));
  1475.  
  1476.        return false;
  1477.    }
  1478.  
  1479.       
  1480.  
  1481. }
  1482.  
  1483.  
  1484.  
  1485. /*
  1486.  * Function:  openRegisterLink(sessionID)
  1487.  *
  1488.  * Arguments: sessionID
  1489.  * Possible values: sessionWatcher (inside sidebar), sessionAppWatcher (from menu)
  1490.  *
  1491.  * Return: None
  1492.  *
  1493.  * Description: This function is called when the register link in sigon overlay is invoked. It opens 
  1494.  * registration url for icq if session is icq. If session is Aim, it opens the regitration wizard.
  1495.  * Note: this is a clone of the function openRegisterLink() in SidebarPanel.js except this getting a  
  1496.  * app-level session element
  1497.  *
  1498.  * Author: Prassanna 4/06/2002
  1499.  */
  1500.  
  1501. function openRegisterLink(sessionID)
  1502. {
  1503.  if(sessionID != null  && sessionID  !=""){
  1504.  
  1505.   var checkSession=window.document.getElementById(sessionID).getAttribute('sessionMode'); 
  1506.   if (checkSession == "Aim")
  1507.     {
  1508.       aimGlobalCmdStartupWizard();
  1509.       return;
  1510.     }
  1511.   else
  1512.     {
  1513.       regLink = aimString("icq.register.url");
  1514.       openTopWin(regLink);  
  1515.       return;
  1516.     }
  1517.  } 
  1518. }
  1519.  
  1520. /*
  1521.  * Function:  cmdIcqSearch()
  1522.  *
  1523.  * Arguments: None
  1524.  * Return: None
  1525.  *
  1526.  * Description: This function is used as a workaround to go to a web page and do user search since we do not support
  1527.  * server side search for Machv.
  1528.  *
  1529.  * Author: Prassanna 4/29/2002
  1530. */
  1531.   
  1532.  
  1533. function cmdIcqSearch()
  1534. {
  1535.    var url=aimString("icq.search.url");
  1536.    if (window.opener) {
  1537.        // From add buddy modal dialog
  1538.        window.opener.openDialog("chrome://navigator/content/navigator.xul", "_blank","modal=no,chrome,chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar", url);
  1539.        return;
  1540.        //Since we have a modal window opening some other window (yuk!), this opener stuff is there
  1541.       // Clean this up post-Machv when real icq search is supported
  1542.    }
  1543.    openDialog("chrome://navigator/content/navigator.xul", "_blank","modal=no,chrome,chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar", url);
  1544. }
  1545.  
  1546.  
  1547. /*
  1548.  * Function: openPrefWindow
  1549.  * Arguments: none
  1550.  * Return: none
  1551.  * Description: opens the pref window based on session type.
  1552.  * Author: Suresh <suresh@netscape.com> 
  1553. */
  1554. function openPrefWindow()
  1555. {
  1556.   if (isIcq())
  1557.     goPreferences('icq', 'chrome://aim/content/pref-Icq_icq.xul','icq');
  1558.   else
  1559.     goPreferences('instantmessenger', 'chrome://aim/content/pref-IM_instantmessage.xul','instantmessenger');
  1560. }
  1561.  
  1562. /* Selects the given index in the buddy list */
  1563. function SelectIndex(index)
  1564. {
  1565.   var tree = getSelectedTreeName();
  1566.   var treeselection = tree.treeBoxObject.selection;
  1567.   treeselection.select(index);
  1568. }
  1569.  
  1570.  
  1571. /*
  1572.  * Function: cachedUserConnection
  1573.  * Arguments: None
  1574.  * Return: connection name
  1575.  * Description: returns AIM or ICQ
  1576.   * Author: Prassanna<prass@netscape.com> 
  1577. */
  1578. function cachedUserConnection()
  1579. {
  1580.   try {
  1581.       if(CachedUserConnection== null)
  1582.             CachedUserConnection= aimPrefsManager().GetCharPref("aim.session.userconnectionname", null, true);
  1583.   } catch (e) {}; 
  1584.   return CachedUserConnection;
  1585. }
  1586.  
  1587. /* Selects the given index in the buddy list */
  1588. function SelectIndex(index)
  1589. {
  1590.   if (aimSession().IsOnline()) {
  1591.     var tree = getSelectedTreeName();
  1592.     var treeselection = tree.treeBoxObject.selection;
  1593.     treeselection.select(index);
  1594.   }
  1595. }
  1596.  
  1597. function getPreaknessFlag()
  1598. {
  1599.   var myaimSession = aimSession();
  1600.   if (myaimSession) {
  1601.     return myaimSession.preaknessFlag;
  1602.   }
  1603.   else
  1604.     return false;
  1605. }
  1606.  
  1607. function aimBuddyIsIcq(screenName)
  1608. {
  1609.   var pIAimBuddy = aimBuddyManager();
  1610.   if ( !screenName || screenName == "" )
  1611.     return false;
  1612.   if(pIAimBuddy)
  1613.     return pIAimBuddy.IsBuddyInIcq(screenName);
  1614. }
  1615.  
  1616.